<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('作品评论列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary single disabled" onclick="batchPass()" >
                    <i class="fa fa-edit"></i> 批量通过
                </a>
                <a class="btn btn-danger multiple disabled" onclick="batchReject()" >
                    <i class="fa fa-remove"></i> 批量驳回
                </a>
                <a class="btn btn-warning" onclick="batchDel()" >
                    <i class="fa fa-download"></i> 批量删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <script th:inline="javascript">
         var editFlag = [[${@permission.hasPermi('comp:comment:edit')}]];
         var removeFlag = [[${@permission.hasPermi('comp:comment:remove')}]];
         var prefix = ctx + "comp/comment";

         $(function() {
             var options = {
                 url: prefix + "/list",
                 createUrl: prefix + "/add",
                 updateUrl: prefix + "/edit/{id}",
                 removeUrl: prefix + "/remove",
                 exportUrl: prefix + "/export",
                 modalName: "作品评论",
                 columns: [{
                     checkbox: true
                 },
                     {
                         field: 'id',
                         title: '评论ID',
                         visible: false
                     },
                     // 作品信息列（关联作品表）
                     {
                         title: '作品信息',
                         formatter: function(value, row, index) {
                             return '<div class="work-info">' +
                                 '<img src="' + row.work.workCover + '" class="work-cover" style="width:50px;height:50px;border-radius:4px;margin-right:10px;">' +
                                 '<div class="work-meta">' +
                                 '<p>' + row.work.title + '</p>' +
                                 '<p>ID: ' + row.id + '</p>' +
                                 '</div>' +
                                 '</div>';
                         }
                     },
                     // 评论人信息列（关联用户表）
                     {
                         title: '评论人信息',
                         formatter: function(value, row, index) {
                             return '<div class="commenter-info">' +
                                 '<img src="' + row.user.avatar + '" class="commenter-avatar" style="width:50px;height:50px;border-radius:4px;margin-right:10px;">' +
                                 '<div class="commenter-meta">' +
                                 '<p>' + row.user.userName + '</p>' +
                                 '<p>ID: ' + row.user.userId + '</p>' +
                                 '</div>' +
                                 '</div>';
                         }
                     },
                     {
                         field: 'content',
                         title: '评论内容',
                         formatter: function(value, row, index) {
                             return '<p>' + value + '</p>' +
                                 '<a class="btn btn-link btn-xs" href="javascript:void(0)" onclick="toggleContent(\'' + index + '\')">收起</a>';
                         }
                     },
                     {
                         field: 'commentTime',
                         title: '评论时间'
                     },
                     {
                         title: '状态',
                         formatter: function(value, row, index) {
                             var userType = "";
                             var color = "status-tag";
                             if (row.status == '0') {
                                 color = "status-tag";
                                 userType = "待审核"
                             } else if(row.status == '1'){
                                 color = "status-tag status-passed";
                                 userType = "已通过";
                             } else if(row.status == '2'){
                                 color = "status-tag status-rejected";
                                 userType = "已驳回";
                             }
                             return '<span class="label label-' + color + '">' + userType + '</span>';
                         }
                     },

                 ]
             };
             $.table.init(options);
         });

         // 评论内容展开/收起逻辑
         function toggleContent(index) {
             var contentEl = $('#bootstrap-table').find('tr:eq(' + (index + 1) + ') td:eq(3) p');
             contentEl.toggle();
         }



         function batchPass() {
             var ids = $.table.selectColumns("id");
             if (ids.length == 0) {
                 $.modal.alertWarning("请至少选择一条记录");
                 return;
             }
             $.modal.confirm("确认要通过选中的" + ids.length + "条数据吗?", function() {
                 var data = {
                     "ids": ids.join(",")  // 明确指定逗号分隔（默认也是逗号，这里更清晰）
                 };
                 $.operate.submit(prefix + "/batchPass", "post", "json", data);
             });
         }

         function batchReject() {
             var ids = $.table.selectColumns("id");
             if (ids.length == 0) {
                 $.modal.alertWarning("请至少选择一条记录");
                 return;
             }
             $.modal.confirm("确认要驳回选中的" + ids.length + "条数据吗?", function() {
                 var data = {
                     "ids": ids.join(",")  // 明确指定逗号分隔（默认也是逗号，这里更清晰）
                 };
                 $.operate.submit(prefix + "/batchReject", "post", "json", data);
             });
         }


         function batchDel() {
             var ids = $.table.selectColumns("id");
             if (ids.length == 0) {
                 $.modal.alertWarning("请至少选择一条记录");
                 return;
             }
             $.modal.confirm("确认要删除选中的" + ids.length + "条数据吗?", function() {
                 var data = {
                     "ids": ids.join(",")  // 明确指定逗号分隔（默认也是逗号，这里更清晰）
                 };
                 $.operate.submit(prefix + "/batchDel", "post", "json", data);
             });
         }



     </script>
</body>
</html>